/**
*@Author: QWP
*@Description: 登录的共享数据
*@Date 2023-08-14 14:58
*/
import { defineStore } from 'pinia'

interface LoginState {
  token: string, // 登录的token信息
  flowToken: string, // 流程的登录的token信息
  refreshToken: string, // 用于刷新的token信息
  userInfo: object, // 用户基本信息
  userAllInfo: object, // 用户全信息
  isMustChange: boolean, // 是否强制修改密码
  smsTime: number, // 短信验证码的倒数时间
}

export const useLoginStore = defineStore('loginStore', {
  state: (): LoginState => {
    return {
      token: '', // 登录的token信息
      flowToken: '', // 流程的登录的token信息
      refreshToken: '', // 用于刷新的token信息
      userInfo: {}, // 用户基本信息
      userAllInfo: {}, // 用户全信息
      isMustChange: false,// 是否强制修改密码
      smsTime: 0
    }
  },
  getters: {
    getToken: (state): string => state.token,
    getRefreshToken: (state): string => state.refreshToken,
    getUserInfo: (state): object => state.userInfo,
    getUserAllInfo: (state): object => state.userAllInfo,
    getIsMustChange: (state): boolean => state.isMustChange,
  },
  actions: {
    setToken(data: string) {
      this.token = data
    },
    setFlowToken(data: string) {
      this.flowToken = data
    },
    setRefreshToken(data: string) {
      this.refreshToken = data
    },
    setUserInfo(data: object) {
      this.userInfo = data
    },
    setUserAllInfo(data: object){
      this.userAllInfo = data
    },
    setIsMustChange(data: boolean) {
      this.isMustChange = data
    },
    setSmsTime(data: number) {
      this.smsTime = data
    },
  },
  persist: true,
})